package com.guoqing.example.service;

import com.guoqing.example.mapper.UserMapper;
import com.guoqing.example.po.User;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author zhangguoqing
 * @Date 2020/8/27
 */
@Service
public class MyService {


    @Autowired
    UserMapper userMapper;

    @Transactional(propagation = Propagation.REQUIRES_NEW)
//    @Transactional
    public void updateRole() {
        System.out.println("-----" + userMapper);
        userMapper.updateRole();
    }


    @Transactional
    public void insertUser() {
        ((MyService) AopContext.currentProxy()).updateRole();
        User u = new User();
        u.setName("zzz");
        u.setGender("nvv");
        u.setPwd("pppwwwddd");
        userMapper.insertUser(u);
        int x = 1 / 0;
    }
}
